////////////////////////////////////////////////////////////////////////////////
//
//  FLEX USER GROUP HOKURIKU
//  Copyright 2009 Flex User Group Hokuriku
//  All Rights Reserved.
// 
//  NOTICE: Flex User Group Hokuriku permits you to use, 
//  modify, and distribute this file 
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package net.fxug.hokuriku.chocolat.helper
{
    import flash.events.Event;

    import mx.core.IMXMLObject;
    import mx.events.FlexEvent;

    import net.fxug.hokuriku.chocolat.events.ViewChangeEvent;
    import net.fxug.hokuriku.chocolat.utils.FilterUtil;
    import net.fxug.hokuriku.chocolat.view.AudienceView;

    /**
     * スピーカー画面のヘルパークラス
     *
     * @author shoito
     */
    public class AudienceViewHelper implements IMXMLObject
    {
        private var view:AudienceView;

        public function initialized(document:Object, id:String):void
        {
            this.view = document as AudienceView;
            this.view.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
            this.view.filters = [FilterUtil.getDropShadowFilter()];
        }

        private function creationCompleteHandler(event:FlexEvent):void
        {
            this.view.setting.addEventListener(ViewChangeEvent.JOIN, setting_joinHandler);
            this.view.setting.addEventListener(ViewChangeEvent.BACK, setting_backHandler);
            this.view.addEventListener(FlexEvent.REMOVE, removeHandler);
        }

        private function setting_joinHandler(event:Event):void
        {
            this.view.currentState = "vote";
            this.view.vote.addEventListener(ViewChangeEvent.BACK, vote_backHandler);
        }

        private function setting_backHandler(event:Event):void
        {
            this.view.dispatchEvent(new ViewChangeEvent(ViewChangeEvent.BACK));
        }

        private function vote_backHandler(event:Event):void
        {
            this.view.currentState = "setting";
        }

        private function removeHandler(event:FlexEvent):void
        {
            this.view.currentState = "setting";
        }
    }
}